home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Doc / libpickle.tex < prev    next >
LaTeX Document  |  1995-12-17  |  9.1 KB  |  [TEXT/R*ch]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text, with CR line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[R*ch]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 53 74 61 6e 64 61 72 |\section|{Standar|
|00000010| 64 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |d Module| \sectco|
|00000020| 64 65 7b 70 69 63 6b 6c | 65 7d 7d 0d 5c 73 74 6d |de{pickl|e}}.\stm|
|00000030| 6f 64 69 6e 64 65 78 7b | 70 69 63 6b 6c 65 7d 0d |odindex{|pickle}.|
|00000040| 5c 69 6e 64 65 78 7b 70 | 65 72 73 69 73 74 65 6e |\index{p|ersisten|
|00000050| 63 79 7d 0d 5c 69 6e 64 | 65 78 69 69 7b 70 65 72 |cy}.\ind|exii{per|
|00000060| 73 69 73 74 65 6e 74 7d | 7b 6f 62 6a 65 63 74 73 |sistent}|{objects|
|00000070| 7d 0d 5c 69 6e 64 65 78 | 69 69 7b 73 65 72 69 61 |}.\index|ii{seria|
|00000080| 6c 69 7a 69 6e 67 7d 7b | 6f 62 6a 65 63 74 73 7d |lizing}{|objects}|
|00000090| 0d 5c 69 6e 64 65 78 69 | 69 7b 6d 61 72 73 68 61 |.\indexi|i{marsha|
|000000a0| 6c 6c 69 6e 67 7d 7b 6f | 62 6a 65 63 74 73 7d 0d |lling}{o|bjects}.|
|000000b0| 5c 69 6e 64 65 78 69 69 | 7b 66 6c 61 74 74 65 6e |\indexii|{flatten|
|000000c0| 69 6e 67 7d 7b 6f 62 6a | 65 63 74 73 7d 0d 5c 69 |ing}{obj|ects}.\i|
|000000d0| 6e 64 65 78 69 69 7b 70 | 69 63 6b 6c 69 6e 67 7d |ndexii{p|ickling}|
|000000e0| 7b 6f 62 6a 65 63 74 73 | 7d 0d 0d 5c 72 65 6e 65 |{objects|}..\rene|
|000000f0| 77 63 6f 6d 6d 61 6e 64 | 7b 5c 69 6e 64 65 78 73 |wcommand|{\indexs|
|00000100| 75 62 69 74 65 6d 7d 7b | 28 69 6e 20 6d 6f 64 75 |ubitem}{|(in modu|
|00000110| 6c 65 20 70 69 63 6b 6c | 65 29 7d 0d 0d 54 68 65 |le pickl|e)}..The|
|00000120| 20 5c 63 6f 64 65 7b 70 | 69 63 6b 6c 65 7d 20 6d | \code{p|ickle} m|
|00000130| 6f 64 75 6c 65 20 69 6d | 70 6c 65 6d 65 6e 74 73 |odule im|plements|
|00000140| 20 61 20 62 61 73 69 63 | 20 62 75 74 20 70 6f 77 | a basic| but pow|
|00000150| 65 72 66 75 6c 20 61 6c | 67 6f 72 69 74 68 6d 20 |erful al|gorithm |
|00000160| 66 6f 72 0d 60 60 70 69 | 63 6b 6c 69 6e 67 27 27 |for.``pi|ckling''|
|00000170| 20 28 61 2e 6b 2e 61 2e | 5c 20 73 65 72 69 61 6c | (a.k.a.|\ serial|
|00000180| 69 7a 69 6e 67 2c 20 6d | 61 72 73 68 61 6c 6c 69 |izing, m|arshalli|
|00000190| 6e 67 20 6f 72 20 66 6c | 61 74 74 65 6e 69 6e 67 |ng or fl|attening|
|000001a0| 29 20 6e 65 61 72 6c 79 | 0d 61 72 62 69 74 72 61 |) nearly|.arbitra|
|000001b0| 72 79 20 50 79 74 68 6f | 6e 20 6f 62 6a 65 63 74 |ry Pytho|n object|
|000001c0| 73 2e 20 20 54 68 69 73 | 20 69 73 20 74 68 65 20 |s. This| is the |
|000001d0| 61 63 74 20 6f 66 20 63 | 6f 6e 76 65 72 74 69 6e |act of c|onvertin|
|000001e0| 67 20 6f 62 6a 65 63 74 | 73 20 74 6f 20 61 0d 73 |g object|s to a.s|
|000001f0| 74 72 65 61 6d 20 6f 66 | 20 62 79 74 65 73 20 28 |tream of| bytes (|
|00000200| 61 6e 64 20 62 61 63 6b | 3a 20 60 60 75 6e 70 69 |and back|: ``unpi|
|00000210| 63 6b 6c 69 6e 67 27 27 | 29 2e 0d 54 68 69 73 20 |ckling''|)..This |
|00000220| 69 73 20 61 20 6d 6f 72 | 65 20 70 72 69 6d 69 74 |is a mor|e primit|
|00000230| 69 76 65 20 6e 6f 74 69 | 6f 6e 20 74 68 61 6e 0d |ive noti|on than.|
|00000240| 70 65 72 73 69 73 74 65 | 6e 63 79 20 2d 2d 2d 20 |persiste|ncy --- |
|00000250| 61 6c 74 68 6f 75 67 68 | 20 5c 63 6f 64 65 7b 70 |although| \code{p|
|00000260| 69 63 6b 6c 65 7d 20 72 | 65 61 64 73 20 61 6e 64 |ickle} r|eads and|
|00000270| 20 77 72 69 74 65 73 20 | 66 69 6c 65 20 6f 62 6a | writes |file obj|
|00000280| 65 63 74 73 2c 0d 69 74 | 20 64 6f 65 73 20 6e 6f |ects,.it| does no|
|00000290| 74 20 68 61 6e 64 6c 65 | 20 74 68 65 20 69 73 73 |t handle| the iss|
|000002a0| 75 65 20 6f 66 20 6e 61 | 6d 69 6e 67 20 70 65 72 |ue of na|ming per|
|000002b0| 73 69 73 74 65 6e 74 20 | 6f 62 6a 65 63 74 73 2c |sistent |objects,|
|000002c0| 20 6e 6f 72 20 74 68 65 | 0d 28 65 76 65 6e 20 6d | nor the|.(even m|
|000002d0| 6f 72 65 20 63 6f 6d 70 | 6c 69 63 61 74 65 64 29 |ore comp|licated)|
|000002e0| 20 61 72 65 61 20 6f 66 | 20 63 6f 6e 63 75 72 72 | area of| concurr|
|000002f0| 65 6e 74 20 61 63 63 65 | 73 73 20 74 6f 20 70 65 |ent acce|ss to pe|
|00000300| 72 73 69 73 74 65 6e 74 | 0d 6f 62 6a 65 63 74 73 |rsistent|.objects|
|00000310| 2e 20 20 54 68 65 20 5c | 63 6f 64 65 7b 70 69 63 |. The \|code{pic|
|00000320| 6b 6c 65 7d 20 6d 6f 64 | 75 6c 65 20 63 61 6e 20 |kle} mod|ule can |
|00000330| 74 72 61 6e 73 66 6f 72 | 6d 20 61 20 63 6f 6d 70 |transfor|m a comp|
|00000340| 6c 65 78 20 6f 62 6a 65 | 63 74 20 69 6e 74 6f 0d |lex obje|ct into.|
|00000350| 61 20 62 79 74 65 20 73 | 74 72 65 61 6d 20 61 6e |a byte s|tream an|
|00000360| 64 20 69 74 20 63 61 6e | 20 74 72 61 6e 73 66 6f |d it can| transfo|
|00000370| 72 6d 20 74 68 65 20 62 | 79 74 65 20 73 74 72 65 |rm the b|yte stre|
|00000380| 61 6d 20 69 6e 74 6f 20 | 61 6e 20 6f 62 6a 65 63 |am into |an objec|
|00000390| 74 20 77 69 74 68 0d 74 | 68 65 20 73 61 6d 65 20 |t with.t|he same |
|000003a0| 69 6e 74 65 72 6e 61 6c | 20 73 74 72 75 63 74 75 |internal| structu|
|000003b0| 72 65 2e 20 20 54 68 65 | 20 6d 6f 73 74 20 6f 62 |re. The| most ob|
|000003c0| 76 69 6f 75 73 20 74 68 | 69 6e 67 20 74 6f 20 64 |vious th|ing to d|
|000003d0| 6f 20 77 69 74 68 20 74 | 68 65 73 65 0d 62 79 74 |o with t|hese.byt|
|000003e0| 65 20 73 74 72 65 61 6d | 73 20 69 73 20 74 6f 20 |e stream|s is to |
|000003f0| 77 72 69 74 65 20 74 68 | 65 6d 20 6f 6e 74 6f 20 |write th|em onto |
|00000400| 61 20 66 69 6c 65 2c 20 | 62 75 74 20 69 74 20 69 |a file, |but it i|
|00000410| 73 20 61 6c 73 6f 20 63 | 6f 6e 63 65 69 76 61 62 |s also c|onceivab|
|00000420| 6c 65 0d 74 6f 20 73 65 | 6e 64 20 74 68 65 6d 20 |le.to se|nd them |
|00000430| 61 63 72 6f 73 73 20 61 | 20 6e 65 74 77 6f 72 6b |across a| network|
|00000440| 20 6f 72 20 73 74 6f 72 | 65 20 74 68 65 6d 20 69 | or stor|e them i|
|00000450| 6e 20 61 20 64 61 74 61 | 62 61 73 65 2e 20 20 54 |n a data|base. T|
|00000460| 68 65 20 6d 6f 64 75 6c | 65 0d 5c 63 6f 64 65 7b |he modul|e.\code{|
|00000470| 73 68 65 6c 76 65 7d 20 | 70 72 6f 76 69 64 65 73 |shelve} |provides|
|00000480| 20 61 20 73 69 6d 70 6c | 65 20 69 6e 74 65 72 66 | a simpl|e interf|
|00000490| 61 63 65 20 74 6f 20 70 | 69 63 6b 6c 65 20 61 6e |ace to p|ickle an|
|000004a0| 64 20 75 6e 70 69 63 6b | 6c 65 0d 6f 62 6a 65 63 |d unpick|le.objec|
|000004b0| 74 73 20 6f 6e 20 60 60 | 64 62 6d 27 27 2d 73 74 |ts on ``|dbm''-st|
|000004c0| 79 6c 65 20 64 61 74 61 | 62 61 73 65 20 66 69 6c |yle data|base fil|
|000004d0| 65 73 2e 0d 5c 73 74 6d | 6f 64 69 6e 64 65 78 7b |es..\stm|odindex{|
|000004e0| 73 68 65 6c 76 65 7d 0d | 0d 55 6e 6c 69 6b 65 20 |shelve}.|.Unlike |
|000004f0| 74 68 65 20 62 75 69 6c | 74 2d 69 6e 20 6d 6f 64 |the buil|t-in mod|
|00000500| 75 6c 65 20 5c 63 6f 64 | 65 7b 6d 61 72 73 68 61 |ule \cod|e{marsha|
|00000510| 6c 7d 2c 20 5c 63 6f 64 | 65 7b 70 69 63 6b 6c 65 |l}, \cod|e{pickle|
|00000520| 7d 20 68 61 6e 64 6c 65 | 73 20 74 68 65 0d 66 6f |} handle|s the.fo|
|00000530| 6c 6c 6f 77 69 6e 67 20 | 63 6f 72 72 65 63 74 6c |llowing |correctl|
|00000540| 79 3a 0d 5c 73 74 6d 6f | 64 69 6e 64 65 78 7b 6d |y:.\stmo|dindex{m|
|00000550| 61 72 73 68 61 6c 7d 0d | 0d 5c 62 65 67 69 6e 7b |arshal}.|.\begin{|
|00000560| 69 74 65 6d 69 7a 65 7d | 0d 0d 5c 69 74 65 6d 20 |itemize}|..\item |
|00000570| 72 65 63 75 72 73 69 76 | 65 20 6f 62 6a 65 63 74 |recursiv|e object|
|00000580| 73 20 28 6f 62 6a 65 63 | 74 73 20 63 6f 6e 74 61 |s (objec|ts conta|
|00000590| 69 6e 69 6e 67 20 72 65 | 66 65 72 65 6e 63 65 73 |ining re|ferences|
|000005a0| 20 74 6f 20 74 68 65 6d | 73 65 6c 76 65 73 29 0d | to them|selves).|
|000005b0| 0d 5c 69 74 65 6d 20 6f | 62 6a 65 63 74 20 73 68 |.\item o|bject sh|
|000005c0| 61 72 69 6e 67 20 28 72 | 65 66 65 72 65 6e 63 65 |aring (r|eference|
|000005d0| 73 20 74 6f 20 74 68 65 | 20 73 61 6d 65 20 6f 62 |s to the| same ob|
|000005e0| 6a 65 63 74 20 69 6e 20 | 64 69 66 66 65 72 65 6e |ject in |differen|
|000005f0| 74 20 70 6c 61 63 65 73 | 29 0d 0d 5c 69 74 65 6d |t places|)..\item|
|00000600| 20 75 73 65 72 2d 64 65 | 66 69 6e 65 64 20 63 6c | user-de|fined cl|
|00000610| 61 73 73 65 73 20 61 6e | 64 20 74 68 65 69 72 20 |asses an|d their |
|00000620| 69 6e 73 74 61 6e 63 65 | 73 0d 0d 5c 65 6e 64 7b |instance|s..\end{|
|00000630| 69 74 65 6d 69 7a 65 7d | 0d 0d 54 68 65 20 64 61 |itemize}|..The da|
|00000640| 74 61 20 66 6f 72 6d 61 | 74 20 75 73 65 64 20 62 |ta forma|t used b|
|00000650| 79 20 5c 63 6f 64 65 7b | 70 69 63 6b 6c 65 7d 20 |y \code{|pickle} |
|00000660| 69 73 20 50 79 74 68 6f | 6e 2d 73 70 65 63 69 66 |is Pytho|n-specif|
|00000670| 69 63 2e 20 20 54 68 69 | 73 20 68 61 73 0d 74 68 |ic. Thi|s has.th|
|00000680| 65 20 61 64 76 61 6e 74 | 61 67 65 20 74 68 61 74 |e advant|age that|
|00000690| 20 74 68 65 72 65 20 61 | 72 65 20 6e 6f 20 72 65 | there a|re no re|
|000006a0| 73 74 72 69 63 74 69 6f | 6e 73 20 69 6d 70 6f 73 |strictio|ns impos|
|000006b0| 65 64 20 62 79 20 65 78 | 74 65 72 6e 61 6c 0d 73 |ed by ex|ternal.s|
|000006c0| 74 61 6e 64 61 72 64 73 | 20 73 75 63 68 20 61 73 |tandards| such as|
|000006d0| 20 43 4f 52 42 41 20 28 | 77 68 69 63 68 20 70 72 | CORBA (|which pr|
|000006e0| 6f 62 61 62 6c 79 20 63 | 61 6e 27 74 20 72 65 70 |obably c|an't rep|
|000006f0| 72 65 73 65 6e 74 20 70 | 6f 69 6e 74 65 72 0d 73 |resent p|ointer.s|
|00000700| 68 61 72 69 6e 67 20 6f | 72 20 72 65 63 75 72 73 |haring o|r recurs|
|00000710| 69 76 65 20 6f 62 6a 65 | 63 74 73 29 3b 20 68 6f |ive obje|cts); ho|
|00000720| 77 65 76 65 72 20 69 74 | 20 6d 65 61 6e 73 20 74 |wever it| means t|
|00000730| 68 61 74 20 6e 6f 6e 2d | 50 79 74 68 6f 6e 0d 70 |hat non-|Python.p|
|00000740| 72 6f 67 72 61 6d 73 20 | 6d 61 79 20 6e 6f 74 20 |rograms |may not |
|00000750| 62 65 20 61 62 6c 65 20 | 74 6f 20 72 65 63 6f 6e |be able |to recon|
|00000760| 73 74 72 75 63 74 20 70 | 69 63 6b 6c 65 64 20 50 |struct p|ickled P|
|00000770| 79 74 68 6f 6e 20 6f 62 | 6a 65 63 74 73 2e 0d 0d |ython ob|jects...|
|00000780| 54 68 65 20 5c 63 6f 64 | 65 7b 70 69 63 6b 6c 65 |The \cod|e{pickle|
|00000790| 7d 20 64 61 74 61 20 66 | 6f 72 6d 61 74 20 75 73 |} data f|ormat us|
|000007a0| 65 73 20 61 20 70 72 69 | 6e 74 61 62 6c 65 20 5c |es a pri|ntable \|
|000007b0| 41 53 43 49 49 7b 7d 20 | 72 65 70 72 65 73 65 6e |ASCII{} |represen|
|000007c0| 74 61 74 69 6f 6e 2e 0d | 54 68 69 73 20 69 73 20 |tation..|This is |
|000007d0| 73 6c 69 67 68 74 6c 79 | 20 6d 6f 72 65 20 76 6f |slightly| more vo|
|000007e0| 6c 75 6d 69 6e 6f 75 73 | 20 74 68 61 6e 20 61 20 |luminous| than a |
|000007f0| 62 69 6e 61 72 79 20 72 | 65 70 72 65 73 65 6e 74 |binary r|epresent|
|00000800| 61 74 69 6f 6e 2e 0d 48 | 6f 77 65 76 65 72 2c 20 |ation..H|owever, |
|00000810| 73 6d 61 6c 6c 20 69 6e | 74 65 67 65 72 73 20 61 |small in|tegers a|
|00000820| 63 74 75 61 6c 6c 79 20 | 74 61 6b 65 20 7b 5c 65 |ctually |take {\e|
|00000830| 6d 20 6c 65 73 73 7d 20 | 73 70 61 63 65 20 77 68 |m less} |space wh|
|00000840| 65 6e 0d 72 65 70 72 65 | 73 65 6e 74 65 64 20 61 |en.repre|sented a|
|00000850| 73 20 6d 69 6e 69 6d 61 | 6c 2d 73 69 7a 65 20 64 |s minima|l-size d|
|00000860| 65 63 69 6d 61 6c 20 73 | 74 72 69 6e 67 73 20 74 |ecimal s|trings t|
|00000870| 68 61 6e 20 77 68 65 6e | 20 72 65 70 72 65 73 65 |han when| represe|
|00000880| 6e 74 65 64 20 61 73 0d | 33 32 2d 62 69 74 20 62 |nted as.|32-bit b|
|00000890| 69 6e 61 72 79 20 6e 75 | 6d 62 65 72 73 2c 20 61 |inary nu|mbers, a|
|000008a0| 6e 64 20 73 74 72 69 6e | 67 73 20 61 72 65 20 6f |nd strin|gs are o|
|000008b0| 6e 6c 79 20 6d 75 63 68 | 20 6c 6f 6e 67 65 72 20 |nly much| longer |
|000008c0| 69 66 20 74 68 65 79 0d | 63 6f 6e 74 61 69 6e 20 |if they.|contain |
|000008d0| 6d 61 6e 79 20 63 6f 6e | 74 72 6f 6c 20 63 68 61 |many con|trol cha|
|000008e0| 72 61 63 74 65 72 73 20 | 6f 72 20 38 2d 62 69 74 |racters |or 8-bit|
|000008f0| 20 63 68 61 72 61 63 74 | 65 72 73 2e 20 20 54 68 | charact|ers. Th|
|00000900| 65 20 62 69 67 0d 61 64 | 76 61 6e 74 61 67 65 20 |e big.ad|vantage |
|00000910| 6f 66 20 75 73 69 6e 67 | 20 70 72 69 6e 74 61 62 |of using| printab|
|00000920| 6c 65 20 5c 41 53 43 49 | 49 7b 7d 20 28 61 6e 64 |le \ASCI|I{} (and|
|00000930| 20 6f 66 20 73 6f 6d 65 | 20 6f 74 68 65 72 20 63 | of some| other c|
|00000940| 68 61 72 61 63 74 65 72 | 69 73 74 69 63 73 0d 6f |haracter|istics.o|
|00000950| 66 20 5c 63 6f 64 65 7b | 70 69 63 6b 6c 65 7d 27 |f \code{|pickle}'|
|00000960| 73 20 72 65 70 72 65 73 | 65 6e 74 61 74 69 6f 6e |s repres|entation|
|00000970| 29 20 69 73 20 74 68 61 | 74 20 66 6f 72 20 64 65 |) is tha|t for de|
|00000980| 62 75 67 67 69 6e 67 20 | 6f 72 20 72 65 63 6f 76 |bugging |or recov|
|00000990| 65 72 79 0d 70 75 72 70 | 6f 73 65 73 20 69 74 20 |ery.purp|oses it |
|000009a0| 69 73 20 70 6f 73 73 69 | 62 6c 65 20 66 6f 72 20 |is possi|ble for |
|000009b0| 61 20 68 75 6d 61 6e 20 | 74 6f 20 72 65 61 64 20 |a human |to read |
|000009c0| 74 68 65 20 70 69 63 6b | 6c 65 64 20 66 69 6c 65 |the pick|led file|
|000009d0| 20 77 69 74 68 20 61 0d | 73 74 61 6e 64 61 72 64 | with a.|standard|
|000009e0| 20 74 65 78 74 20 65 64 | 69 74 6f 72 2e 20 20 28 | text ed|itor. (|
|000009f0| 49 20 63 6f 75 6c 64 20 | 68 61 76 65 20 67 6f 6e |I could |have gon|
|00000a00| 65 20 61 20 73 74 65 70 | 20 66 75 72 74 68 65 72 |e a step| further|
|00000a10| 20 61 6e 64 20 75 73 65 | 64 20 61 0d 6e 6f 74 61 | and use|d a.nota|
|00000a20| 74 69 6f 6e 20 6c 69 6b | 65 20 53 2d 65 78 70 72 |tion lik|e S-expr|
|00000a30| 65 73 73 69 6f 6e 73 2c | 20 62 75 74 20 74 68 65 |essions,| but the|
|00000a40| 20 70 61 72 73 65 72 0d | 28 63 75 72 72 65 6e 74 | parser.|(current|
|00000a50| 6c 79 20 77 72 69 74 74 | 65 6e 20 69 6e 20 50 79 |ly writt|en in Py|
|00000a60| 74 68 6f 6e 29 20 77 6f | 75 6c 64 20 68 61 76 65 |thon) wo|uld have|
|00000a70| 20 62 65 65 6e 0d 63 6f | 6e 73 69 64 65 72 61 62 | been.co|nsiderab|
|00000a80| 6c 79 20 6d 6f 72 65 20 | 63 6f 6d 70 6c 69 63 61 |ly more |complica|
|00000a90| 74 65 64 20 61 6e 64 20 | 73 6c 6f 77 65 72 2c 20 |ted and |slower, |
|00000aa0| 61 6e 64 20 74 68 65 20 | 66 69 6c 65 73 20 77 6f |and the |files wo|
|00000ab0| 75 6c 64 20 70 72 6f 62 | 61 62 6c 79 0d 68 61 76 |uld prob|ably.hav|
|00000ac0| 65 20 62 65 63 6f 6d 65 | 20 6d 75 63 68 20 6c 61 |e become| much la|
|00000ad0| 72 67 65 72 2e 29 0d 0d | 54 68 65 20 5c 63 6f 64 |rger.)..|The \cod|
|00000ae0| 65 7b 70 69 63 6b 6c 65 | 7d 20 6d 6f 64 75 6c 65 |e{pickle|} module|
|00000af0| 20 64 6f 65 73 6e 27 74 | 20 68 61 6e 64 6c 65 20 | doesn't| handle |
|00000b00| 63 6f 64 65 20 6f 62 6a | 65 63 74 73 2c 20 77 68 |code obj|ects, wh|
|00000b10| 69 63 68 20 74 68 65 0d | 5c 63 6f 64 65 7b 6d 61 |ich the.|\code{ma|
|00000b20| 72 73 68 61 6c 7d 20 6d | 6f 64 75 6c 65 20 64 6f |rshal} m|odule do|
|00000b30| 65 73 2e 20 20 49 20 73 | 75 70 70 6f 73 65 20 5c |es. I s|uppose \|
|00000b40| 63 6f 64 65 7b 70 69 63 | 6b 6c 65 7d 20 63 6f 75 |code{pic|kle} cou|
|00000b50| 6c 64 2c 20 61 6e 64 20 | 6d 61 79 62 65 0d 69 74 |ld, and |maybe.it|
|00000b60| 20 73 68 6f 75 6c 64 2c | 20 62 75 74 20 74 68 65 | should,| but the|
|00000b70| 72 65 27 73 20 70 72 6f | 62 61 62 6c 79 20 6e 6f |re's pro|bably no|
|00000b80| 20 67 72 65 61 74 20 6e | 65 65 64 20 66 6f 72 20 | great n|eed for |
|00000b90| 69 74 20 72 69 67 68 74 | 20 6e 6f 77 20 28 61 73 |it right| now (as|
|00000ba0| 0d 6c 6f 6e 67 20 61 73 | 20 5c 63 6f 64 65 7b 6d |.long as| \code{m|
|00000bb0| 61 72 73 68 61 6c 7d 20 | 63 6f 6e 74 69 6e 75 65 |arshal} |continue|
|00000bc0| 73 20 74 6f 20 62 65 20 | 75 73 65 64 20 66 6f 72 |s to be |used for|
|00000bd0| 20 72 65 61 64 69 6e 67 | 20 61 6e 64 20 77 72 69 | reading| and wri|
|00000be0| 74 69 6e 67 0d 63 6f 64 | 65 20 6f 62 6a 65 63 74 |ting.cod|e object|
|00000bf0| 73 29 2c 20 61 6e 64 20 | 61 74 20 6c 65 61 73 74 |s), and |at least|
|00000c00| 20 74 68 69 73 20 61 76 | 6f 69 64 73 20 74 68 65 | this av|oids the|
|00000c10| 20 70 6f 73 73 69 62 69 | 6c 69 74 79 20 6f 66 20 | possibi|lity of |
|00000c20| 73 6d 75 67 67 6c 69 6e | 67 0d 54 72 6f 6a 61 6e |smugglin|g.Trojan|
|00000c30| 20 68 6f 72 73 65 73 20 | 69 6e 74 6f 20 61 20 70 | horses |into a p|
|00000c40| 72 6f 67 72 61 6d 2e 0d | 5c 73 74 6d 6f 64 69 6e |rogram..|\stmodin|
|00000c50| 64 65 78 7b 6d 61 72 73 | 68 61 6c 7d 0d 0d 46 6f |dex{mars|hal}..Fo|
|00000c60| 72 20 74 68 65 20 62 65 | 6e 65 66 69 74 20 6f 66 |r the be|nefit of|
|00000c70| 20 70 65 72 73 69 73 74 | 65 6e 63 79 20 6d 6f 64 | persist|ency mod|
|00000c80| 75 6c 65 73 20 77 72 69 | 74 74 65 6e 20 75 73 69 |ules wri|tten usi|
|00000c90| 6e 67 20 5c 63 6f 64 65 | 7b 70 69 63 6b 6c 65 7d |ng \code|{pickle}|
|00000ca0| 2c 20 69 74 0d 73 75 70 | 70 6f 72 74 73 20 74 68 |, it.sup|ports th|
|00000cb0| 65 20 6e 6f 74 69 6f 6e | 20 6f 66 20 61 20 72 65 |e notion| of a re|
|00000cc0| 66 65 72 65 6e 63 65 20 | 74 6f 20 61 6e 20 6f 62 |ference |to an ob|
|00000cd0| 6a 65 63 74 20 6f 75 74 | 73 69 64 65 20 74 68 65 |ject out|side the|
|00000ce0| 20 70 69 63 6b 6c 65 64 | 0d 64 61 74 61 20 73 74 | pickled|.data st|
|00000cf0| 72 65 61 6d 2e 20 20 53 | 75 63 68 20 6f 62 6a 65 |ream. S|uch obje|
|00000d00| 63 74 73 20 61 72 65 20 | 72 65 66 65 72 65 6e 63 |cts are |referenc|
|00000d10| 65 64 20 62 79 20 61 20 | 6e 61 6d 65 2c 20 77 68 |ed by a |name, wh|
|00000d20| 69 63 68 20 69 73 20 61 | 6e 0d 61 72 62 69 74 72 |ich is a|n.arbitr|
|00000d30| 61 72 79 20 73 74 72 69 | 6e 67 20 6f 66 20 70 72 |ary stri|ng of pr|
|00000d40| 69 6e 74 61 62 6c 65 20 | 5c 41 53 43 49 49 7b 7d |intable |\ASCII{}|
|00000d50| 20 63 68 61 72 61 63 74 | 65 72 73 2e 20 20 54 68 | charact|ers. Th|
|00000d60| 65 20 72 65 73 6f 6c 75 | 74 69 6f 6e 20 6f 66 0d |e resolu|tion of.|
|00000d70| 73 75 63 68 20 6e 61 6d | 65 73 20 69 73 20 6e 6f |such nam|es is no|
|00000d80| 74 20 64 65 66 69 6e 65 | 64 20 62 79 20 74 68 65 |t define|d by the|
|00000d90| 20 5c 63 6f 64 65 7b 70 | 69 63 6b 6c 65 7d 20 6d | \code{p|ickle} m|
|00000da0| 6f 64 75 6c 65 20 2d 2d | 2d 20 74 68 65 0d 70 65 |odule --|- the.pe|
|00000db0| 72 73 69 73 74 65 6e 74 | 20 6f 62 6a 65 63 74 20 |rsistent| object |
|00000dc0| 6d 6f 64 75 6c 65 20 77 | 69 6c 6c 20 68 61 76 65 |module w|ill have|
|00000dd0| 20 74 6f 20 69 6d 70 6c | 65 6d 65 6e 74 20 61 20 | to impl|ement a |
|00000de0| 6d 65 74 68 6f 64 0d 5c | 63 6f 64 65 7b 70 65 72 |method.\|code{per|
|00000df0| 73 69 73 74 65 6e 74 5f | 6c 6f 61 64 7d 2e 20 20 |sistent_|load}. |
|00000e00| 54 6f 20 77 72 69 74 65 | 20 72 65 66 65 72 65 6e |To write| referen|
|00000e10| 63 65 73 20 74 6f 20 70 | 65 72 73 69 73 74 65 6e |ces to p|ersisten|
|00000e20| 74 20 6f 62 6a 65 63 74 | 73 2c 0d 74 68 65 20 70 |t object|s,.the p|
|00000e30| 65 72 73 69 73 74 65 6e | 74 20 6d 6f 64 75 6c 65 |ersisten|t module|
|00000e40| 20 6d 75 73 74 20 64 65 | 66 69 6e 65 20 61 20 6d | must de|fine a m|
|00000e50| 65 74 68 6f 64 20 5c 63 | 6f 64 65 7b 70 65 72 73 |ethod \c|ode{pers|
|00000e60| 69 73 74 65 6e 74 5f 69 | 64 7d 20 77 68 69 63 68 |istent_i|d} which|
|00000e70| 0d 72 65 74 75 72 6e 73 | 20 65 69 74 68 65 72 20 |.returns| either |
|00000e80| 5c 63 6f 64 65 7b 4e 6f | 6e 65 7d 20 6f 72 20 74 |\code{No|ne} or t|
|00000e90| 68 65 20 70 65 72 73 69 | 73 74 65 6e 74 20 49 44 |he persi|stent ID|
|00000ea0| 20 6f 66 20 74 68 65 20 | 6f 62 6a 65 63 74 2e 0d | of the |object..|
|00000eb0| 0d 54 68 65 72 65 20 61 | 72 65 20 73 6f 6d 65 20 |.There a|re some |
|00000ec0| 72 65 73 74 72 69 63 74 | 69 6f 6e 73 20 6f 6e 20 |restrict|ions on |
|00000ed0| 74 68 65 20 70 69 63 6b | 6c 69 6e 67 20 6f 66 20 |the pick|ling of |
|00000ee0| 63 6c 61 73 73 20 69 6e | 73 74 61 6e 63 65 73 2e |class in|stances.|
|00000ef0| 0d 0d 46 69 72 73 74 20 | 6f 66 20 61 6c 6c 2c 20 |..First |of all, |
|00000f00| 74 68 65 20 63 6c 61 73 | 73 20 6d 75 73 74 20 62 |the clas|s must b|
|00000f10| 65 20 64 65 66 69 6e 65 | 64 20 61 74 20 74 68 65 |e define|d at the|
|00000f20| 20 74 6f 70 20 6c 65 76 | 65 6c 20 69 6e 20 61 20 | top lev|el in a |
|00000f30| 6d 6f 64 75 6c 65 2e 0d | 0d 5c 72 65 6e 65 77 63 |module..|.\renewc|
|00000f40| 6f 6d 6d 61 6e 64 7b 5c | 69 6e 64 65 78 73 75 62 |ommand{\|indexsub|
|00000f50| 69 74 65 6d 7d 7b 28 70 | 69 63 6b 6c 65 20 70 72 |item}{(p|ickle pr|
|00000f60| 6f 74 6f 63 6f 6c 29 7d | 0d 0d 4e 65 78 74 2c 20 |otocol)}|..Next, |
|00000f70| 69 74 20 6d 75 73 74 20 | 6e 6f 72 6d 61 6c 6c 79 |it must |normally|
|00000f80| 20 62 65 20 70 6f 73 73 | 69 62 6c 65 20 74 6f 20 | be poss|ible to |
|00000f90| 63 72 65 61 74 65 20 63 | 6c 61 73 73 20 69 6e 73 |create c|lass ins|
|00000fa0| 74 61 6e 63 65 73 20 62 | 79 0d 63 61 6c 6c 69 6e |tances b|y.callin|
|00000fb0| 67 20 74 68 65 20 63 6c | 61 73 73 20 77 69 74 68 |g the cl|ass with|
|00000fc0| 6f 75 74 20 61 72 67 75 | 6d 65 6e 74 73 2e 20 20 |out argu|ments. |
|00000fd0| 49 66 20 74 68 69 73 20 | 69 73 20 75 6e 64 65 73 |If this |is undes|
|00000fe0| 69 72 61 62 6c 65 2c 20 | 74 68 65 0d 63 6c 61 73 |irable, |the.clas|
|00000ff0| 73 20 63 61 6e 20 64 65 | 66 69 6e 65 20 61 20 6d |s can de|fine a m|
|00001000| 65 74 68 6f 64 20 5c 63 | 6f 64 65 7b 5f 5f 67 65 |ethod \c|ode{__ge|
|00001010| 74 69 6e 69 74 61 72 67 | 73 5f 5f 28 29 7d 2c 20 |tinitarg|s__()}, |
|00001020| 77 68 69 63 68 20 73 68 | 6f 75 6c 64 0d 72 65 74 |which sh|ould.ret|
|00001030| 75 72 6e 20 61 20 7b 5c | 65 6d 20 74 75 70 6c 65 |urn a {\|em tuple|
|00001040| 7d 20 63 6f 6e 74 61 69 | 6e 69 6e 67 20 74 68 65 |} contai|ning the|
|00001050| 20 61 72 67 75 6d 65 6e | 74 73 20 74 6f 20 62 65 | argumen|ts to be|
|00001060| 20 70 61 73 73 65 64 20 | 74 6f 20 74 68 65 0d 63 | passed |to the.c|
|00001070| 6c 61 73 73 20 63 6f 6e | 73 74 72 75 63 74 6f 72 |lass con|structor|
|00001080| 20 28 5c 63 6f 64 65 7b | 5f 5f 69 6e 69 74 5f 5f | (\code{|__init__|
|00001090| 28 29 7d 29 2e 0d 5c 74 | 74 69 6e 64 65 78 7b 5f |()})..\t|tindex{_|
|000010a0| 5f 67 65 74 69 6e 69 74 | 61 72 67 73 5f 5f 7d 0d |_getinit|args__}.|
|000010b0| 5c 74 74 69 6e 64 65 78 | 7b 5f 5f 69 6e 69 74 5f |\ttindex|{__init_|
|000010c0| 5f 7d 0d 0d 43 6c 61 73 | 73 65 73 20 63 61 6e 20 |_}..Clas|ses can |
|000010d0| 66 75 72 74 68 65 72 20 | 69 6e 66 6c 75 65 6e 63 |further |influenc|
|000010e0| 65 20 68 6f 77 20 74 68 | 65 69 72 20 69 6e 73 74 |e how th|eir inst|
|000010f0| 61 6e 63 65 73 20 61 72 | 65 20 70 69 63 6b 6c 65 |ances ar|e pickle|
|00001100| 64 20 2d 2d 2d 20 69 66 | 20 74 68 65 20 63 6c 61 |d --- if| the cla|
|00001110| 73 73 0d 64 65 66 69 6e | 65 73 20 74 68 65 20 6d |ss.defin|es the m|
|00001120| 65 74 68 6f 64 20 5c 63 | 6f 64 65 7b 5f 5f 67 65 |ethod \c|ode{__ge|
|00001130| 74 73 74 61 74 65 5f 5f | 28 29 7d 2c 20 69 74 20 |tstate__|()}, it |
|00001140| 69 73 20 63 61 6c 6c 65 | 64 20 61 6e 64 20 74 68 |is calle|d and th|
|00001150| 65 20 72 65 74 75 72 6e | 0d 73 74 61 74 65 20 69 |e return|.state i|
|00001160| 73 20 70 69 63 6b 6c 65 | 64 20 61 73 20 74 68 65 |s pickle|d as the|
|00001170| 20 63 6f 6e 74 65 6e 74 | 73 20 66 6f 72 20 74 68 | content|s for th|
|00001180| 65 20 69 6e 73 74 61 6e | 63 65 2c 20 61 6e 64 20 |e instan|ce, and |
|00001190| 69 66 20 74 68 65 20 63 | 6c 61 73 73 0d 64 65 66 |if the c|lass.def|
|000011a0| 69 6e 65 73 20 74 68 65 | 20 6d 65 74 68 6f 64 20 |ines the| method |
|000011b0| 5c 63 6f 64 65 7b 5f 5f | 73 65 74 73 74 61 74 65 |\code{__|setstate|
|000011c0| 5f 5f 28 29 7d 2c 20 69 | 74 20 69 73 20 63 61 6c |__()}, i|t is cal|
|000011d0| 6c 65 64 20 77 69 74 68 | 20 74 68 65 0d 75 6e 70 |led with| the.unp|
|000011e0| 69 63 6b 6c 65 64 20 73 | 74 61 74 65 2e 20 20 28 |ickled s|tate. (|
|000011f0| 4e 6f 74 65 20 74 68 61 | 74 20 74 68 65 73 65 20 |Note tha|t these |
|00001200| 6d 65 74 68 6f 64 73 20 | 63 61 6e 20 61 6c 73 6f |methods |can also|
|00001210| 20 62 65 20 75 73 65 64 | 20 74 6f 0d 69 6d 70 6c | be used| to.impl|
|00001220| 65 6d 65 6e 74 20 63 6f | 70 79 69 6e 67 20 63 6c |ement co|pying cl|
|00001230| 61 73 73 20 69 6e 73 74 | 61 6e 63 65 73 2e 29 20 |ass inst|ances.) |
|00001240| 20 49 66 20 74 68 65 72 | 65 20 69 73 20 6e 6f 0d | If ther|e is no.|
|00001250| 5c 63 6f 64 65 7b 5f 5f | 67 65 74 73 74 61 74 65 |\code{__|getstate|
|00001260| 5f 5f 28 29 7d 20 6d 65 | 74 68 6f 64 2c 20 74 68 |__()} me|thod, th|
|00001270| 65 20 69 6e 73 74 61 6e | 63 65 27 73 20 5c 63 6f |e instan|ce's \co|
|00001280| 64 65 7b 5f 5f 64 69 63 | 74 5f 5f 7d 20 69 73 0d |de{__dic|t__} is.|
|00001290| 70 69 63 6b 6c 65 64 2e | 20 20 49 66 20 74 68 65 |pickled.| If the|
|000012a0| 72 65 20 69 73 20 6e 6f | 20 5c 63 6f 64 65 7b 5f |re is no| \code{_|
|000012b0| 5f 73 65 74 73 74 61 74 | 65 5f 5f 28 29 7d 20 6d |_setstat|e__()} m|
|000012c0| 65 74 68 6f 64 2c 20 74 | 68 65 20 70 69 63 6b 6c |ethod, t|he pickl|
|000012d0| 65 64 0d 6f 62 6a 65 63 | 74 20 6d 75 73 74 20 62 |ed.objec|t must b|
|000012e0| 65 20 61 20 64 69 63 74 | 69 6f 6e 61 72 79 20 61 |e a dict|ionary a|
|000012f0| 6e 64 20 69 74 73 20 69 | 74 65 6d 73 20 61 72 65 |nd its i|tems are|
|00001300| 20 61 73 73 69 67 6e 65 | 64 20 74 6f 20 74 68 65 | assigne|d to the|
|00001310| 20 6e 65 77 0d 69 6e 73 | 74 61 6e 63 65 27 73 20 | new.ins|tance's |
|00001320| 64 69 63 74 69 6f 6e 61 | 72 79 2e 20 20 28 49 66 |dictiona|ry. (If|
|00001330| 20 61 20 63 6c 61 73 73 | 20 64 65 66 69 6e 65 73 | a class| defines|
|00001340| 20 62 6f 74 68 20 5c 63 | 6f 64 65 7b 5f 5f 67 65 | both \c|ode{__ge|
|00001350| 74 73 74 61 74 65 5f 5f | 28 29 7d 0d 61 6e 64 20 |tstate__|()}.and |
|00001360| 5c 63 6f 64 65 7b 5f 5f | 73 65 74 73 74 61 74 65 |\code{__|setstate|
|00001370| 5f 5f 28 29 7d 2c 20 74 | 68 65 20 73 74 61 74 65 |__()}, t|he state|
|00001380| 20 6f 62 6a 65 63 74 20 | 6e 65 65 64 6e 27 74 20 | object |needn't |
|00001390| 62 65 20 61 20 64 69 63 | 74 69 6f 6e 61 72 79 0d |be a dic|tionary.|
|000013a0| 2d 2d 2d 20 74 68 65 73 | 65 20 6d 65 74 68 6f 64 |--- thes|e method|
|000013b0| 73 20 63 61 6e 20 64 6f | 20 77 68 61 74 20 74 68 |s can do| what th|
|000013c0| 65 79 20 77 61 6e 74 2e | 29 20 20 54 68 69 73 20 |ey want.|) This |
|000013d0| 70 72 6f 74 6f 63 6f 6c | 20 69 73 20 61 6c 73 6f |protocol| is also|
|000013e0| 20 75 73 65 64 0d 62 79 | 20 74 68 65 20 73 68 61 | used.by| the sha|
|000013f0| 6c 6c 6f 77 20 61 6e 64 | 20 64 65 65 70 20 63 6f |llow and| deep co|
|00001400| 70 79 69 6e 67 20 6f 70 | 65 72 61 74 69 6f 6e 73 |pying op|erations|
|00001410| 20 64 65 66 69 6e 65 64 | 20 69 6e 20 74 68 65 20 | defined| in the |
|00001420| 5c 63 6f 64 65 7b 63 6f | 70 79 7d 0d 6d 6f 64 75 |\code{co|py}.modu|
|00001430| 6c 65 2e 0d 5c 74 74 69 | 6e 64 65 78 7b 5f 5f 67 |le..\tti|ndex{__g|
|00001440| 65 74 73 74 61 74 65 5f | 5f 7d 0d 5c 74 74 69 6e |etstate_|_}.\ttin|
|00001450| 64 65 78 7b 5f 5f 73 65 | 74 73 74 61 74 65 5f 5f |dex{__se|tstate__|
|00001460| 7d 0d 5c 74 74 69 6e 64 | 65 78 7b 5f 5f 64 69 63 |}.\ttind|ex{__dic|
|00001470| 74 5f 5f 7d 0d 0d 4e 6f | 74 65 20 74 68 61 74 20 |t__}..No|te that |
|00001480| 77 68 65 6e 20 63 6c 61 | 73 73 20 69 6e 73 74 61 |when cla|ss insta|
|00001490| 6e 63 65 73 20 61 72 65 | 20 70 69 63 6b 6c 65 64 |nces are| pickled|
|000014a0| 2c 20 74 68 65 69 72 20 | 63 6c 61 73 73 27 73 20 |, their |class's |
|000014b0| 63 6f 64 65 20 61 6e 64 | 0d 64 61 74 61 20 61 72 |code and|.data ar|
|000014c0| 65 20 6e 6f 74 20 70 69 | 63 6b 6c 65 64 20 61 6c |e not pi|ckled al|
|000014d0| 6f 6e 67 20 77 69 74 68 | 20 74 68 65 6d 2e 20 20 |ong with| them. |
|000014e0| 4f 6e 6c 79 20 74 68 65 | 20 69 6e 73 74 61 6e 63 |Only the| instanc|
|000014f0| 65 20 64 61 74 61 20 61 | 72 65 0d 70 69 63 6b 6c |e data a|re.pickl|
|00001500| 65 64 2e 20 20 54 68 69 | 73 20 69 73 20 64 6f 6e |ed. Thi|s is don|
|00001510| 65 20 6f 6e 20 70 75 72 | 70 6f 73 65 2c 20 73 6f |e on pur|pose, so|
|00001520| 20 79 6f 75 20 63 61 6e | 20 66 69 78 20 62 75 67 | you can| fix bug|
|00001530| 73 20 69 6e 20 61 20 63 | 6c 61 73 73 20 6f 72 0d |s in a c|lass or.|
|00001540| 61 64 64 20 6d 65 74 68 | 6f 64 73 20 61 6e 64 20 |add meth|ods and |
|00001550| 73 74 69 6c 6c 20 6c 6f | 61 64 20 6f 62 6a 65 63 |still lo|ad objec|
|00001560| 74 73 20 74 68 61 74 20 | 77 65 72 65 20 63 72 65 |ts that |were cre|
|00001570| 61 74 65 64 20 77 69 74 | 68 20 61 6e 20 65 61 72 |ated wit|h an ear|
|00001580| 6c 69 65 72 0d 76 65 72 | 73 69 6f 6e 20 6f 66 20 |lier.ver|sion of |
|00001590| 74 68 65 20 63 6c 61 73 | 73 2e 20 20 49 66 20 79 |the clas|s. If y|
|000015a0| 6f 75 20 70 6c 61 6e 20 | 74 6f 20 68 61 76 65 20 |ou plan |to have |
|000015b0| 6c 6f 6e 67 2d 6c 69 76 | 65 64 20 6f 62 6a 65 63 |long-liv|ed objec|
|000015c0| 74 73 20 74 68 61 74 0d | 77 69 6c 6c 20 73 65 65 |ts that.|will see|
|000015d0| 20 6d 61 6e 79 20 76 65 | 72 73 69 6f 6e 73 20 6f | many ve|rsions o|
|000015e0| 66 20 61 20 63 6c 61 73 | 73 2c 20 69 74 20 6d 61 |f a clas|s, it ma|
|000015f0| 79 20 62 65 20 77 6f 72 | 74 68 77 68 69 6c 65 20 |y be wor|thwhile |
|00001600| 74 6f 20 70 75 74 20 61 | 20 76 65 72 73 69 6f 6e |to put a| version|
|00001610| 0d 6e 75 6d 62 65 72 20 | 69 6e 20 74 68 65 20 6f |.number |in the o|
|00001620| 62 6a 65 63 74 73 20 73 | 6f 20 74 68 61 74 20 73 |bjects s|o that s|
|00001630| 75 69 74 61 62 6c 65 20 | 63 6f 6e 76 65 72 73 69 |uitable |conversi|
|00001640| 6f 6e 73 20 63 61 6e 20 | 62 65 20 6d 61 64 65 20 |ons can |be made |
|00001650| 62 79 20 74 68 65 0d 63 | 6c 61 73 73 27 73 20 5c |by the.c|lass's \|
|00001660| 63 6f 64 65 7b 5f 5f 73 | 65 74 73 74 61 74 65 5f |code{__s|etstate_|
|00001670| 5f 28 29 7d 20 6d 65 74 | 68 6f 64 2e 0d 0d 57 68 |_()} met|hod...Wh|
|00001680| 65 6e 20 61 20 63 6c 61 | 73 73 20 69 74 73 65 6c |en a cla|ss itsel|
|00001690| 66 20 69 73 20 70 69 63 | 6b 6c 65 64 2c 20 6f 6e |f is pic|kled, on|
|000016a0| 6c 79 20 69 74 73 20 6e | 61 6d 65 20 69 73 20 70 |ly its n|ame is p|
|000016b0| 69 63 6b 6c 65 64 20 2d | 2d 2d 20 74 68 65 20 63 |ickled -|-- the c|
|000016c0| 6c 61 73 73 0d 64 65 66 | 69 6e 69 74 69 6f 6e 20 |lass.def|inition |
|000016d0| 69 73 20 6e 6f 74 20 70 | 69 63 6b 6c 65 64 2c 20 |is not p|ickled, |
|000016e0| 62 75 74 20 72 65 2d 69 | 6d 70 6f 72 74 65 64 20 |but re-i|mported |
|000016f0| 62 79 20 74 68 65 20 75 | 6e 70 69 63 6b 6c 69 6e |by the u|npicklin|
|00001700| 67 20 70 72 6f 63 65 73 | 73 2e 0d 54 68 65 72 65 |g proces|s..There|
|00001710| 66 6f 72 65 2c 20 74 68 | 65 20 72 65 73 74 72 69 |fore, th|e restri|
|00001720| 63 74 69 6f 6e 20 74 68 | 61 74 20 74 68 65 20 63 |ction th|at the c|
|00001730| 6c 61 73 73 20 6d 75 73 | 74 20 62 65 20 64 65 66 |lass mus|t be def|
|00001740| 69 6e 65 64 20 61 74 20 | 74 68 65 20 74 6f 70 0d |ined at |the top.|
|00001750| 6c 65 76 65 6c 20 69 6e | 20 61 20 6d 6f 64 75 6c |level in| a modul|
|00001760| 65 20 61 70 70 6c 69 65 | 73 20 74 6f 20 70 69 63 |e applie|s to pic|
|00001770| 6b 6c 65 64 20 63 6c 61 | 73 73 65 73 20 61 73 20 |kled cla|sses as |
|00001780| 77 65 6c 6c 2e 0d 0d 5c | 72 65 6e 65 77 63 6f 6d |well...\|renewcom|
|00001790| 6d 61 6e 64 7b 5c 69 6e | 64 65 78 73 75 62 69 74 |mand{\in|dexsubit|
|000017a0| 65 6d 7d 7b 28 69 6e 20 | 6d 6f 64 75 6c 65 20 70 |em}{(in |module p|
|000017b0| 69 63 6b 6c 65 29 7d 0d | 0d 54 68 65 20 69 6e 74 |ickle)}.|.The int|
|000017c0| 65 72 66 61 63 65 20 63 | 61 6e 20 62 65 20 73 75 |erface c|an be su|
|000017d0| 6d 6d 61 72 69 7a 65 64 | 20 61 73 20 66 6f 6c 6c |mmarized| as foll|
|000017e0| 6f 77 73 2e 0d 0d 54 6f | 20 70 69 63 6b 6c 65 20 |ows...To| pickle |
|000017f0| 61 6e 20 6f 62 6a 65 63 | 74 20 5c 63 6f 64 65 7b |an objec|t \code{|
|00001800| 78 7d 20 6f 6e 74 6f 20 | 61 20 66 69 6c 65 20 5c |x} onto |a file \|
|00001810| 63 6f 64 65 7b 66 7d 2c | 20 6f 70 65 6e 20 66 6f |code{f},| open fo|
|00001820| 72 20 77 72 69 74 69 6e | 67 3a 0d 0d 5c 62 65 67 |r writin|g:..\beg|
|00001830| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 70 20 3d |in{verba|tim}.p =|
|00001840| 20 70 69 63 6b 6c 65 2e | 50 69 63 6b 6c 65 72 28 | pickle.|Pickler(|
|00001850| 66 29 0d 70 2e 64 75 6d | 70 28 78 29 0d 5c 65 6e |f).p.dum|p(x).\en|
|00001860| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0d 0d 41 20 73 |d{verbat|im}..A s|
|00001870| 68 6f 72 74 68 61 6e 64 | 20 66 6f 72 20 74 68 69 |horthand| for thi|
|00001880| 73 20 69 73 3a 0d 0d 5c | 62 65 67 69 6e 7b 76 65 |s is:..\|begin{ve|
|00001890| 72 62 61 74 69 6d 7d 0d | 70 69 63 6b 6c 65 2e 64 |rbatim}.|pickle.d|
|000018a0| 75 6d 70 28 78 2c 20 66 | 29 0d 5c 65 6e 64 7b 76 |ump(x, f|).\end{v|
|000018b0| 65 72 62 61 74 69 6d 7d | 0d 0d 54 6f 20 75 6e 70 |erbatim}|..To unp|
|000018c0| 69 63 6b 6c 65 20 61 6e | 20 6f 62 6a 65 63 74 20 |ickle an| object |
|000018d0| 5c 63 6f 64 65 7b 78 7d | 20 66 72 6f 6d 20 61 20 |\code{x}| from a |
|000018e0| 66 69 6c 65 20 5c 63 6f | 64 65 7b 66 7d 2c 20 6f |file \co|de{f}, o|
|000018f0| 70 65 6e 20 66 6f 72 20 | 72 65 61 64 69 6e 67 3a |pen for |reading:|
|00001900| 0d 0d 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |..\begin|{verbati|
|00001910| 6d 7d 0d 75 20 3d 20 70 | 69 63 6b 6c 65 2e 55 6e |m}.u = p|ickle.Un|
|00001920| 70 69 63 6b 6c 65 72 28 | 66 29 0d 78 20 3d 20 75 |pickler(|f).x = u|
|00001930| 2e 6c 6f 61 64 28 29 0d | 5c 65 6e 64 7b 76 65 72 |.load().|\end{ver|
|00001940| 62 61 74 69 6d 7d 0d 0d | 41 20 73 68 6f 72 74 68 |batim}..|A shorth|
|00001950| 61 6e 64 20 69 73 3a 0d | 0d 5c 62 65 67 69 6e 7b |and is:.|.\begin{|
|00001960| 76 65 72 62 61 74 69 6d | 7d 0d 78 20 3d 20 70 69 |verbatim|}.x = pi|
|00001970| 63 6b 6c 65 2e 6c 6f 61 | 64 28 66 29 0d 5c 65 6e |ckle.loa|d(f).\en|
|00001980| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0d 0d 54 68 65 |d{verbat|im}..The|
|00001990| 20 5c 63 6f 64 65 7b 50 | 69 63 6b 6c 65 72 7d 20 | \code{P|ickler} |
|000019a0| 63 6c 61 73 73 20 6f 6e | 6c 79 20 63 61 6c 6c 73 |class on|ly calls|
|000019b0| 20 74 68 65 20 6d 65 74 | 68 6f 64 20 5c 63 6f 64 | the met|hod \cod|
|000019c0| 65 7b 66 2e 77 72 69 74 | 65 7d 20 77 69 74 68 20 |e{f.writ|e} with |
|000019d0| 61 0d 73 74 72 69 6e 67 | 20 61 72 67 75 6d 65 6e |a.string| argumen|
|000019e0| 74 2e 20 20 54 68 65 20 | 5c 63 6f 64 65 7b 55 6e |t. The |\code{Un|
|000019f0| 70 69 63 6b 6c 65 72 7d | 20 63 61 6c 6c 73 20 74 |pickler}| calls t|
|00001a00| 68 65 20 6d 65 74 68 6f | 64 73 20 5c 63 6f 64 65 |he metho|ds \code|
|00001a10| 7b 66 2e 72 65 61 64 7d | 0d 28 77 69 74 68 20 61 |{f.read}|.(with a|
|00001a20| 6e 20 69 6e 74 65 67 65 | 72 20 61 72 67 75 6d 65 |n intege|r argume|
|00001a30| 6e 74 29 20 61 6e 64 20 | 5c 63 6f 64 65 7b 66 2e |nt) and |\code{f.|
|00001a40| 72 65 61 64 6c 69 6e 65 | 7d 20 28 77 69 74 68 6f |readline|} (witho|
|00001a50| 75 74 20 61 72 67 75 6d | 65 6e 74 29 2c 0d 62 6f |ut argum|ent),.bo|
|00001a60| 74 68 20 72 65 74 75 72 | 6e 69 6e 67 20 61 20 73 |th retur|ning a s|
|00001a70| 74 72 69 6e 67 2e 20 20 | 49 74 20 69 73 20 65 78 |tring. |It is ex|
|00001a80| 70 6c 69 63 69 74 6c 79 | 20 61 6c 6c 6f 77 65 64 |plicitly| allowed|
|00001a90| 20 74 6f 20 70 61 73 73 | 20 6e 6f 6e 2d 66 69 6c | to pass| non-fil|
|00001aa0| 65 0d 6f 62 6a 65 63 74 | 73 20 68 65 72 65 2c 20 |e.object|s here, |
|00001ab0| 61 73 20 6c 6f 6e 67 20 | 61 73 20 74 68 65 79 20 |as long |as they |
|00001ac0| 68 61 76 65 20 74 68 65 | 20 72 69 67 68 74 20 6d |have the| right m|
|00001ad0| 65 74 68 6f 64 73 2e 0d | 5c 74 74 69 6e 64 65 78 |ethods..|\ttindex|
|00001ae0| 7b 55 6e 70 69 63 6b 6c | 65 72 7d 0d 5c 74 74 69 |{Unpickl|er}.\tti|
|00001af0| 6e 64 65 78 7b 50 69 63 | 6b 6c 65 72 7d 0d 0d 54 |ndex{Pic|kler}..T|
|00001b00| 68 65 20 66 6f 6c 6c 6f | 77 69 6e 67 20 74 79 70 |he follo|wing typ|
|00001b10| 65 73 20 63 61 6e 20 62 | 65 20 70 69 63 6b 6c 65 |es can b|e pickle|
|00001b20| 64 3a 0d 5c 62 65 67 69 | 6e 7b 69 74 65 6d 69 7a |d:.\begi|n{itemiz|
|00001b30| 65 7d 0d 0d 5c 69 74 65 | 6d 20 5c 63 6f 64 65 7b |e}..\ite|m \code{|
|00001b40| 4e 6f 6e 65 7d 0d 0d 5c | 69 74 65 6d 20 69 6e 74 |None}..\|item int|
|00001b50| 65 67 65 72 73 2c 20 6c | 6f 6e 67 20 69 6e 74 65 |egers, l|ong inte|
|00001b60| 67 65 72 73 2c 20 66 6c | 6f 61 74 69 6e 67 20 70 |gers, fl|oating p|
|00001b70| 6f 69 6e 74 20 6e 75 6d | 62 65 72 73 0d 0d 5c 69 |oint num|bers..\i|
|00001b80| 74 65 6d 20 73 74 72 69 | 6e 67 73 0d 0d 5c 69 74 |tem stri|ngs..\it|
|00001b90| 65 6d 20 74 75 70 6c 65 | 73 2c 20 6c 69 73 74 73 |em tuple|s, lists|
|00001ba0| 20 61 6e 64 20 64 69 63 | 74 69 6f 6e 61 72 69 65 | and dic|tionarie|
|00001bb0| 73 20 63 6f 6e 74 61 69 | 6e 69 6e 67 20 6f 6e 6c |s contai|ning onl|
|00001bc0| 79 20 70 69 63 6b 6c 61 | 62 6c 65 20 6f 62 6a 65 |y pickla|ble obje|
|00001bd0| 63 74 73 0d 0d 5c 69 74 | 65 6d 20 63 6c 61 73 73 |cts..\it|em class|
|00001be0| 65 73 20 74 68 61 74 20 | 61 72 65 20 64 65 66 69 |es that |are defi|
|00001bf0| 6e 65 64 20 61 74 20 74 | 68 65 20 74 6f 70 20 6c |ned at t|he top l|
|00001c00| 65 76 65 6c 20 69 6e 20 | 61 20 6d 6f 64 75 6c 65 |evel in |a module|
|00001c10| 0d 0d 5c 69 74 65 6d 20 | 69 6e 73 74 61 6e 63 65 |..\item |instance|
|00001c20| 73 20 6f 66 20 73 75 63 | 68 20 63 6c 61 73 73 65 |s of suc|h classe|
|00001c30| 73 20 77 68 6f 73 65 20 | 5c 63 6f 64 65 7b 5f 5f |s whose |\code{__|
|00001c40| 64 69 63 74 5f 5f 7d 20 | 6f 72 0d 5c 63 6f 64 65 |dict__} |or.\code|
|00001c50| 7b 5f 5f 73 65 74 73 74 | 61 74 65 5f 5f 28 29 7d |{__setst|ate__()}|
|00001c60| 20 69 73 20 70 69 63 6b | 6c 61 62 6c 65 0d 0d 5c | is pick|lable..\|
|00001c70| 65 6e 64 7b 69 74 65 6d | 69 7a 65 7d 0d 0d 41 74 |end{item|ize}..At|
|00001c80| 74 65 6d 70 74 73 20 74 | 6f 20 70 69 63 6b 6c 65 |tempts t|o pickle|
|00001c90| 20 75 6e 70 69 63 6b 6c | 61 62 6c 65 20 6f 62 6a | unpickl|able obj|
|00001ca0| 65 63 74 73 20 77 69 6c | 6c 20 72 61 69 73 65 20 |ects wil|l raise |
|00001cb0| 74 68 65 0d 5c 63 6f 64 | 65 7b 50 69 63 6b 6c 69 |the.\cod|e{Pickli|
|00001cc0| 6e 67 45 72 72 6f 72 7d | 20 65 78 63 65 70 74 69 |ngError}| excepti|
|00001cd0| 6f 6e 3b 20 77 68 65 6e | 20 74 68 69 73 20 68 61 |on; when| this ha|
|00001ce0| 70 70 65 6e 73 2c 20 61 | 6e 20 75 6e 73 70 65 63 |ppens, a|n unspec|
|00001cf0| 69 66 69 65 64 0d 6e 75 | 6d 62 65 72 20 6f 66 20 |ified.nu|mber of |
|00001d00| 62 79 74 65 73 20 6d 61 | 79 20 68 61 76 65 20 62 |bytes ma|y have b|
|00001d10| 65 65 6e 20 77 72 69 74 | 74 65 6e 20 74 6f 20 74 |een writ|ten to t|
|00001d20| 68 65 20 66 69 6c 65 2e | 0d 0d 49 74 20 69 73 20 |he file.|..It is |
|00001d30| 70 6f 73 73 69 62 6c 65 | 20 74 6f 20 6d 61 6b 65 |possible| to make|
|00001d40| 20 6d 75 6c 74 69 70 6c | 65 20 63 61 6c 6c 73 20 | multipl|e calls |
|00001d50| 74 6f 20 74 68 65 20 5c | 63 6f 64 65 7b 64 75 6d |to the \|code{dum|
|00001d60| 70 28 29 7d 20 6d 65 74 | 68 6f 64 20 6f 66 0d 74 |p()} met|hod of.t|
|00001d70| 68 65 20 73 61 6d 65 20 | 5c 63 6f 64 65 7b 50 69 |he same |\code{Pi|
|00001d80| 63 6b 6c 65 72 7d 20 69 | 6e 73 74 61 6e 63 65 2e |ckler} i|nstance.|
|00001d90| 20 20 54 68 65 73 65 20 | 6d 75 73 74 20 74 68 65 | These |must the|
|00001da0| 6e 20 62 65 20 6d 61 74 | 63 68 65 64 20 74 6f 20 |n be mat|ched to |
|00001db0| 74 68 65 0d 73 61 6d 65 | 20 6e 75 6d 62 65 72 20 |the.same| number |
|00001dc0| 6f 66 20 63 61 6c 6c 73 | 20 74 6f 20 74 68 65 20 |of calls| to the |
|00001dd0| 5c 63 6f 64 65 7b 6c 6f | 61 64 28 29 7d 20 69 6e |\code{lo|ad()} in|
|00001de0| 73 74 61 6e 63 65 20 6f | 66 20 74 68 65 0d 63 6f |stance o|f the.co|
|00001df0| 72 72 65 73 70 6f 6e 64 | 69 6e 67 20 5c 63 6f 64 |rrespond|ing \cod|
|00001e00| 65 7b 55 6e 70 69 63 6b | 6c 65 72 7d 20 69 6e 73 |e{Unpick|ler} ins|
|00001e10| 74 61 6e 63 65 2e 20 20 | 49 66 20 74 68 65 20 73 |tance. |If the s|
|00001e20| 61 6d 65 20 6f 62 6a 65 | 63 74 20 69 73 0d 70 69 |ame obje|ct is.pi|
|00001e30| 63 6b 6c 65 64 20 62 79 | 20 6d 75 6c 74 69 70 6c |ckled by| multipl|
|00001e40| 65 20 5c 63 6f 64 65 7b | 64 75 6d 70 28 29 7d 20 |e \code{|dump()} |
|00001e50| 63 61 6c 6c 73 2c 20 74 | 68 65 20 5c 63 6f 64 65 |calls, t|he \code|
|00001e60| 7b 6c 6f 61 64 28 29 7d | 20 77 69 6c 6c 20 61 6c |{load()}| will al|
|00001e70| 6c 0d 79 69 65 6c 64 20 | 72 65 66 65 72 65 6e 63 |l.yield |referenc|
|00001e80| 65 73 20 74 6f 20 74 68 | 65 20 73 61 6d 65 20 6f |es to th|e same o|
|00001e90| 62 6a 65 63 74 2e 20 20 | 7b 5c 65 6d 20 57 61 72 |bject. |{\em War|
|00001ea0| 6e 69 6e 67 7d 3a 20 74 | 68 69 73 20 69 73 20 69 |ning}: t|his is i|
|00001eb0| 6e 74 65 6e 64 65 64 0d | 66 6f 72 20 70 69 63 6b |ntended.|for pick|
|00001ec0| 6c 69 6e 67 20 6d 75 6c | 74 69 70 6c 65 20 6f 62 |ling mul|tiple ob|
|00001ed0| 6a 65 63 74 73 20 77 69 | 74 68 6f 75 74 20 69 6e |jects wi|thout in|
|00001ee0| 74 65 72 76 65 6e 69 6e | 67 20 6d 6f 64 69 66 69 |tervenin|g modifi|
|00001ef0| 63 61 74 69 6f 6e 73 20 | 74 6f 20 74 68 65 0d 6f |cations |to the.o|
|00001f00| 62 6a 65 63 74 73 20 6f | 72 20 74 68 65 69 72 20 |bjects o|r their |
|00001f10| 70 61 72 74 73 2e 20 20 | 49 66 20 79 6f 75 20 6d |parts. |If you m|
|00001f20| 6f 64 69 66 79 20 61 6e | 20 6f 62 6a 65 63 74 20 |odify an| object |
|00001f30| 61 6e 64 20 74 68 65 6e | 20 70 69 63 6b 6c 65 20 |and then| pickle |
|00001f40| 69 74 0d 61 67 61 69 6e | 20 75 73 69 6e 67 20 74 |it.again| using t|
|00001f50| 68 65 20 73 61 6d 65 20 | 5c 63 6f 64 65 7b 50 69 |he same |\code{Pi|
|00001f60| 63 6b 6c 65 72 7d 20 69 | 6e 73 74 61 6e 63 65 2c |ckler} i|nstance,|
|00001f70| 20 74 68 65 20 6f 62 6a | 65 63 74 20 69 73 20 6e | the obj|ect is n|
|00001f80| 6f 74 0d 70 69 63 6b 6c | 65 64 20 61 67 61 69 6e |ot.pickl|ed again|
|00001f90| 20 2d 2d 2d 20 61 20 72 | 65 66 65 72 65 6e 63 65 | --- a r|eference|
|00001fa0| 20 74 6f 20 69 74 20 69 | 73 20 70 69 63 6b 6c 65 | to it i|s pickle|
|00001fb0| 64 20 61 6e 64 20 74 68 | 65 0d 5c 63 6f 64 65 7b |d and th|e.\code{|
|00001fc0| 55 6e 70 69 63 6b 6c 65 | 72 7d 20 77 69 6c 6c 20 |Unpickle|r} will |
|00001fd0| 72 65 74 75 72 6e 20 74 | 68 65 20 6f 6c 64 20 76 |return t|he old v|
|00001fe0| 61 6c 75 65 2c 20 6e 6f | 74 20 74 68 65 20 6d 6f |alue, no|t the mo|
|00001ff0| 64 69 66 69 65 64 20 6f | 6e 65 2e 0d 28 54 68 65 |dified o|ne..(The|
|00002000| 72 65 20 61 72 65 20 74 | 77 6f 20 70 72 6f 62 6c |re are t|wo probl|
|00002010| 65 6d 73 20 68 65 72 65 | 3a 20 28 61 29 20 64 65 |ems here|: (a) de|
|00002020| 74 65 63 74 69 6e 67 20 | 63 68 61 6e 67 65 73 2c |tecting |changes,|
|00002030| 20 61 6e 64 20 28 62 29 | 0d 6d 61 72 73 68 61 6c | and (b)|.marshal|
|00002040| 6c 69 6e 67 20 61 20 6d | 69 6e 69 6d 61 6c 20 73 |ling a m|inimal s|
|00002050| 65 74 20 6f 66 20 63 68 | 61 6e 67 65 73 2e 20 20 |et of ch|anges. |
|00002060| 49 20 68 61 76 65 20 6e | 6f 20 61 6e 73 77 65 72 |I have n|o answer|
|00002070| 73 2e 20 20 47 61 72 62 | 61 67 65 0d 43 6f 6c 6c |s. Garb|age.Coll|
|00002080| 65 63 74 69 6f 6e 20 6d | 61 79 20 61 6c 73 6f 20 |ection m|ay also |
|00002090| 62 65 63 6f 6d 65 20 61 | 20 70 72 6f 62 6c 65 6d |become a| problem|
|000020a0| 20 68 65 72 65 2e 29 0d | 0d 41 70 61 72 74 20 66 | here.).|.Apart f|
|000020b0| 72 6f 6d 20 74 68 65 20 | 5c 63 6f 64 65 7b 50 69 |rom the |\code{Pi|
|000020c0| 63 6b 6c 65 72 7d 20 61 | 6e 64 20 5c 63 6f 64 65 |ckler} a|nd \code|
|000020d0| 7b 55 6e 70 69 63 6b 6c | 65 72 7d 20 63 6c 61 73 |{Unpickl|er} clas|
|000020e0| 73 65 73 2c 20 74 68 65 | 0d 6d 6f 64 75 6c 65 20 |ses, the|.module |
|000020f0| 64 65 66 69 6e 65 73 20 | 74 68 65 20 66 6f 6c 6c |defines |the foll|
|00002100| 6f 77 69 6e 67 20 66 75 | 6e 63 74 69 6f 6e 73 2c |owing fu|nctions,|
|00002110| 20 61 6e 64 20 61 6e 20 | 65 78 63 65 70 74 69 6f | and an |exceptio|
|00002120| 6e 3a 0d 0d 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |n:..\beg|in{funcd|
|00002130| 65 73 63 7d 7b 64 75 6d | 70 7d 7b 6f 62 6a 65 63 |esc}{dum|p}{objec|
|00002140| 74 5c 2c 20 66 69 6c 65 | 7d 0d 57 72 69 74 65 20 |t\, file|}.Write |
|00002150| 61 20 70 69 63 6b 6c 65 | 64 20 72 65 70 72 65 73 |a pickle|d repres|
|00002160| 65 6e 74 61 74 69 6f 6e | 20 6f 66 20 5c 76 61 72 |entation| of \var|
|00002170| 7b 6f 62 65 63 74 7d 20 | 74 6f 20 74 68 65 20 6f |{obect} |to the o|
|00002180| 70 65 6e 20 66 69 6c 65 | 20 6f 62 6a 65 63 74 0d |pen file| object.|
|00002190| 5c 76 61 72 7b 66 69 6c | 65 7d 2e 20 20 54 68 69 |\var{fil|e}. Thi|
|000021a0| 73 20 69 73 20 65 71 75 | 69 76 61 6c 65 6e 74 20 |s is equ|ivalent |
|000021b0| 74 6f 20 5c 63 6f 64 65 | 7b 50 69 63 6b 6c 65 72 |to \code|{Pickler|
|000021c0| 28 66 69 6c 65 29 2e 64 | 75 6d 70 28 6f 62 6a 65 |(file).d|ump(obje|
|000021d0| 63 74 29 7d 2e 0d 5c 65 | 6e 64 7b 66 75 6e 63 64 |ct)}..\e|nd{funcd|
|000021e0| 65 73 63 7d 0d 0d 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|000021f0| 63 64 65 73 63 7d 7b 6c | 6f 61 64 7d 7b 66 69 6c |cdesc}{l|oad}{fil|
|00002200| 65 7d 0d 52 65 61 64 20 | 61 20 70 69 63 6b 6c 65 |e}.Read |a pickle|
|00002210| 64 20 6f 62 6a 65 63 74 | 20 66 72 6f 6d 20 74 68 |d object| from th|
|00002220| 65 20 6f 70 65 6e 20 66 | 69 6c 65 20 6f 62 6a 65 |e open f|ile obje|
|00002230| 63 74 20 5c 76 61 72 7b | 66 69 6c 65 7d 2e 20 20 |ct \var{|file}. |
|00002240| 54 68 69 73 20 69 73 0d | 65 71 75 69 76 61 6c 65 |This is.|equivale|
|00002250| 6e 74 20 74 6f 20 5c 63 | 6f 64 65 7b 55 6e 70 69 |nt to \c|ode{Unpi|
|00002260| 63 6b 6c 65 72 28 66 69 | 6c 65 29 2e 6c 6f 61 64 |ckler(fi|le).load|
|00002270| 28 29 7d 2e 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |()}..\en|d{funcde|
|00002280| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00002290| 64 65 73 63 7d 7b 64 75 | 6d 70 73 7d 7b 6f 62 6a |desc}{du|mps}{obj|
|000022a0| 65 63 74 7d 0d 52 65 74 | 75 72 6e 20 74 68 65 20 |ect}.Ret|urn the |
|000022b0| 70 69 63 6b 6c 65 64 20 | 72 65 70 72 65 73 65 6e |pickled |represen|
|000022c0| 74 61 74 69 6f 6e 20 6f | 66 20 74 68 65 20 6f 62 |tation o|f the ob|
|000022d0| 6a 65 63 74 20 61 73 20 | 61 20 73 74 72 69 6e 67 |ject as |a string|
|000022e0| 2c 20 69 6e 73 74 65 61 | 64 0d 6f 66 20 77 72 69 |, instea|d.of wri|
|000022f0| 74 69 6e 67 20 69 74 20 | 74 6f 20 61 20 66 69 6c |ting it |to a fil|
|00002300| 65 2e 0d 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |e..\end{|funcdesc|
|00002310| 7d 0d 0d 5c 62 65 67 69 | 6e 7b 66 75 6e 63 64 65 |}..\begi|n{funcde|
|00002320| 73 63 7d 7b 6c 6f 61 64 | 73 7d 7b 73 74 72 69 6e |sc}{load|s}{strin|
|00002330| 67 7d 0d 52 65 61 64 20 | 61 20 70 69 63 6b 6c 65 |g}.Read |a pickle|
|00002340| 64 20 6f 62 6a 65 63 74 | 20 66 72 6f 6d 20 61 20 |d object| from a |
|00002350| 73 74 72 69 6e 67 20 69 | 6e 73 74 65 61 64 20 6f |string i|nstead o|
|00002360| 66 20 61 20 66 69 6c 65 | 2e 20 20 43 68 61 72 61 |f a file|. Chara|
|00002370| 63 74 65 72 73 20 69 6e | 0d 74 68 65 20 73 74 72 |cters in|.the str|
|00002380| 69 6e 67 20 70 61 73 74 | 20 74 68 65 20 70 69 63 |ing past| the pic|
|00002390| 6b 6c 65 64 20 6f 62 6a | 65 63 74 27 73 20 72 65 |kled obj|ect's re|
|000023a0| 70 72 65 73 65 6e 74 61 | 74 69 6f 6e 20 61 72 65 |presenta|tion are|
|000023b0| 20 69 67 6e 6f 72 65 64 | 2e 0d 5c 65 6e 64 7b 66 | ignored|..\end{f|
|000023c0| 75 6e 63 64 65 73 63 7d | 0d 0d 5c 62 65 67 69 6e |uncdesc}|..\begin|
|000023d0| 7b 65 78 63 64 65 73 63 | 7d 7b 50 69 63 6b 6c 69 |{excdesc|}{Pickli|
|000023e0| 6e 67 45 72 72 6f 72 7d | 0d 54 68 69 73 20 65 78 |ngError}|.This ex|
|000023f0| 63 65 70 74 69 6f 6e 20 | 69 73 20 72 61 69 73 65 |ception |is raise|
|00002400| 64 20 77 68 65 6e 20 61 | 6e 20 75 6e 70 69 63 6b |d when a|n unpick|
|00002410| 6c 61 62 6c 65 20 6f 62 | 6a 65 63 74 20 69 73 20 |lable ob|ject is |
|00002420| 70 61 73 73 65 64 20 74 | 6f 0d 5c 63 6f 64 65 7b |passed t|o.\code{|
|00002430| 50 69 63 6b 6c 65 72 2e | 64 75 6d 70 28 29 7d 2e |Pickler.|dump()}.|
|00002440| 0d 5c 65 6e 64 7b 65 78 | 63 64 65 73 63 7d 0d |.\end{ex|cdesc}. |
+--------+-------------------------+-------------------------+--------+--------+